{extend name="layout" /}
{block name="content"}
<div class="layui-tab layui-tab-brief">
	<ul class="layui-tab-title">
	    <li class="layui-this">{$pathCurrent['name']}</li>
  	</ul>
<!-- </div>
<div class="fileBox" style="margin-top: 25px;margin-left:20px;">

	<button class="layui-btn" id="uploadExcel" data-type="">批量导入</button>
	<button class="layui-btn" id="excelDemo" data-type="excelDemo" style="margin-left:10px;" >表格模板下载</button>
</div> -->

<div class="demoTable" style="margin-top: 25px;margin-left:20px;">
	业务员：
	<div class="layui-inline">
		<input class="layui-input" name="like" id="like" placeholder="" style="width:220px;"  autocomplete="off">
	</div>

	
	<button class="layui-btn" data-type="reload">搜索</button>
</div>
<div class="layui-card-body">
	<div data-model="table-bind">
		<table class="layui-hide" id="data_table" lay-filter="data_table" data-table></table>
	</div>
</div>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
	</div>
  </script>
<script type="text/html" id="barTar">
	<a class="layui-btn layui-btn-xs" lay-event="son">明细</a>
</script>
<script type="text/html" id="image">
	<img src="{{d.image}}" height="30">
</script>
<script type="text/html" id="sysTar">
	{{#  if(d.status == 1){ }}
  	<button type="button" class="layui-btn layui-btn-normal">正常</button>
  	{{#  } else { }}
  	<button type="button" class="layui-btn layui-btn-danger">关闭</button>
  	{{#  } }}
</script>
{/block}
{block name="js"}
<script type="text/javascript">
var mixin = {};
var SlefUrl = this.location.href;
layui.use(['table','upload'], function(){
	var table = layui.table
		,upload = layui.upload;
	table.render({
		elem: '#data_table',
		url:SlefUrl,
        toolbar: '#toolbarDemo',
        defaultToolbar: ['filter', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
            title: '导出Excel'
            ,layEvent: 'LAYTABLE_Excel'
            ,icon: 'layui-icon layui-icon-export'
        }],
		limit:20,
		cellMinWidth: 80,
		cols: [[
	      	// {field:'id',width:80, title: 'ID', sort: true,align:'center'}
	      	{field:'sn', title: '业务员编号', width:180,align:'center'}
	      	,{field:'name', title: '业务员名称'}
	      	,{field:'c_num', title: '分配数量'}
            ,{field:'res_num', title: '已核销数量',sort: true,align:'center'}
            ,{field:'res_mark', title: '剩余数量',sort: true,align:'center'}
	      	,{field:'op', title: '操作',toolbar: '#barTar', width:150,align:'center'}
	    ]],
	    page: true,
        id: 'testReload'
	});


	table.on('tool(data_table)', function(obj){
		var data = obj.data;
		data.table = "goods";
		if(obj.event === 'del'){
			layer.confirm('确定删除吗？', function(index){
	        	layer.close(index);
	       		form.formDel(data,obj);
	      	});
		}

        if(obj.event === 'son') {
            layer.open({
                type: 2
                ,offset: 'auto'
                ,content: '{:url("lists")}'+'?id='+ data.id+'&type=1'
                ,btnAlign: 'c' //按钮居中
                ,shade: 0.8 //不显示遮罩
				,area : [ '800px', '600px' ]
                ,yes: function(){
                    layer.closeAll();
                }
            });

        }
	});

    //头工具栏事件
    table.on('toolbar(data_table)', function(obj){

        if(obj.event === 'LAYTABLE_Excel'){
            var result = {};
            result.customer_id = $('#customer_id').val();
            result.goods_id = $('#goods_id').val();
            result.staff_id = $('#staff_id').val();
            result.like = $('#like').val();
            result.start_time = $('#start_time').val();
            result.end_time = $('#end_time').val();

            DownLoadFile({'url':''+webRoot+ webControl+'/load_excel?type=1','data':result})
        }

    });



    var $ = layui.$, active = {
        reload: function(){
            var like = $('#like');

            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    like: like.val()
                }
            }, 'data');
		},
		
		excelDemo: function(){
            window.location.href = '/excel/product_demo.xls'
        }


    };

	upload.render({
		elem: '#uploadExcel'
		,url: '{:url("savestudentImport")}'
		,accept: 'file' //普通文件
		,auto:'xlsx|xls|csv'
		,done: function(res){
			layer.alert(res.msg);
			// setInterval(function(){
			// 	window.location.reload();
			// },3000)
			
		}
	});

    $('.demoTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	$('#excelDemo').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    var DownLoadFile = function (options) {
        var config = $.extend(true, { method: 'post' }, options);
        var $iframe = $('<iframe id="down-file-iframe" />');
        var $form = $('<form target="down-file-iframe" method="' + config.method + '" />');
        $form.attr('action', config.url);
        for (var key in config.data) {
            $form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" />');
        }
        $iframe.append($form);
        $(document.body).append($iframe);
        $form[0].submit();
        $iframe.remove();
    }



});
</script>
{/block}